#!/usr/bin/env bash

# Author: Zhang Huangbin <zhb _at_ iredmail.org>

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# Variables for Postfix and related.

#
# You do *NOT* need to modify them.
#
# ---- Postfix ----
export SYS_USER_POSTFIX='postfix'
export SYS_GROUP_POSTFIX='postfix'

export POSTFIX_ROOTDIR='/etc/postfix'
export POSTFIX_RC_SCRIPT_NAME='postfix'

# Log file
export MAILLOG='/var/log/maillog'

if [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
    export MAILLOG='/var/log/mail.log'
    export MAILLOG_INFO='/var/log/mail.info'
    export MAILLOG_ERROR='/var/log/mail.err'
    export MAILLOG_WARN='/var/log/mail.warn'

elif [ X"${DISTRO}" == X'FREEBSD' ]; then
    export POSTFIX_ROOTDIR='/usr/local/etc/postfix'

elif [ X"${DISTRO}" == X'OPENBSD' ]; then
    export SYS_USER_POSTFIX='_postfix'
    export SYS_GROUP_POSTFIX='_postfix'
fi

# You do *NOT* need to modify them.
export POSTFIX_CHROOT_DIR='/var/spool/postfix'

export POSTFIX_FILE_MAIN_CF="${POSTFIX_ROOTDIR}/main.cf"
export POSTFIX_FILE_MASTER_CF="${POSTFIX_ROOTDIR}/master.cf"
export POSTFIX_FILE_ALIASES="${POSTFIX_ROOTDIR}/aliases"
export POSTFIX_FILE_HELO_ACCESS="${POSTFIX_ROOTDIR}/helo_access.pcre"
export POSTFIX_FILE_SMTPD_COMMAND_FILTER="${POSTFIX_ROOTDIR}/command_filter.pcre"

export POSTFIX_FILE_HEADER_CHECKS="${POSTFIX_ROOTDIR}/header_checks"
export POSTFIX_FILE_BODY_CHECKS="${POSTFIX_ROOTDIR}/body_checks.pcre"
# used for sender white/blacklist with pcre support
export POSTFIX_FILE_SENDER_ACCESS="${POSTFIX_ROOTDIR}/sender_access.pcre"

export POSTSCREEN_FILE_DNSBL_REPLY="${POSTFIX_ROOTDIR}/postscreen_dnsbl_reply"
export POSTSCREEN_FILE_ACCESS_CIDR="${POSTFIX_ROOTDIR}/postscreen_access.cidr"

# Default transport or LDA (local deliver agent).
export TRANSPORT="${TRANSPORT:=${DOVECOT_LDA_DELIVER}}"

# Set 'message_size_limit', in 'byte' and 'kilobytes'.
# Default is 15M (final message will be slight larger after encoding).
export MESSAGE_SIZE_LIMIT_MB="${MESSAGE_SIZE_LIMIT_MB:=15}"
export MESSAGE_SIZE_LIMIT_BYTES="$((MESSAGE_SIZE_LIMIT_MB * 1024 * 1024))"
export MESSAGE_SIZE_LIMIT_KB="$((MESSAGE_SIZE_LIMIT_MB * 1024))"

# LDAP/MYSQL/PGSQL lookup configuration files.
if [ X"${BACKEND}" == X'OPENLDAP' ]; then
    export POSTFIX_LOOKUP_DB='ldap'
elif [ X"${BACKEND}" == X'MYSQL' ]; then
    export POSTFIX_LOOKUP_DB='mysql'
elif [ X"${BACKEND}" == X'PGSQL' ]; then
    export POSTFIX_LOOKUP_DB='pgsql'
else
    export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/lookups"
fi

export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/${POSTFIX_LOOKUP_DB}"
export POSTFIX_MAIL_REINJECT_PORT='10025'
export POSTFIX_MLMMJ_REINJECT_PORT='10028'
